package actors

import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.{ActorContext, Behaviors}

object Aggregator {

  import Messages._

  def apply(): Behavior[UserProtocol] = {
    Behaviors.receive{ (context: ActorContext[UserProtocol], message: UserProtocol) =>
      message match {
        case DeviceRegisteredResponse(newCamera) =>
          context.log.info(s"[aggregator] New Camera Device: $newCamera - is successfully registered!")
          Behaviors.same
        case DeviceInfoUpdatedResponse(cameraDevice) =>
          context.log.info(s"[aggregator] Updated device information: $cameraDevice")
          Behaviors.same
        case GetDeviceInfoResponse(cameraDevice) =>
          context.log.info(s"[aggregator] Device information: $cameraDevice")
          Behaviors.same
        case DeviceUnregisterResponse =>
          context.log.info("[aggregator] Device is successfully unregistered!")
          Behaviors.same
        case RegistrationFailure(reason) =>
          context.log.info(s"[aggregator] Device registration failed due to: ${reason.getMessage}")
          Behaviors.same
        case ExecutionFailed(reason) =>
          context.log.info(s"[aggregator] Execution failed due to: ${reason.getMessage}")
          Behaviors.same
      }
    }
  }
}
